<template>
  <div :class="className">
    <!-- style -->
    <!--<div v-html="css"></div>-->

    <div class="fixed-box set-pc-style" :style="box_style">
      <!--悬浮按钮静态-->
      <div class="btn" :style="button_style" @click.stop="toUrl">{{ title }}</div>
    </div>

    <van-popup v-model="showPop" closeable round style="width: 85%;padding: 24px;">
      <div class="t-c f-16">
        <div class="f-18 f-bold">{{ title }}</div>
        <img :src="datas.pop_image" alt="" class="w-100 margin-top-10" />
        <div class="flex-column flex-a-c">
          <div class="margin-top-6 flex" :style="{ color: datas.pop_phone_color }">
            联系方式：<a class="f-grow-1 t-l" :href="`tel:${datas.pop_phone}`">{{ datas.pop_phone }}</a>
          </div>
          <div class="margin-top-6 flex-a-c" :style="{ color: datas.pop_wx_color }" v-clipboard:copy="datas.pop_wx" v-clipboard:success="onCopy" v-clipboard:error="onError">
            微信号：{{ datas.pop_wx }} <div class="margin-left-6 f-14" style="color: #F15353;">复制</div>
          </div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
export default {
  props: ["id", "datas", "styles"],
  data() {
    return {
      showPop: false
    };
  },
  components: {},
  mounted() {},
  computed: {
    box_style() {
      const { button_size, over_bottom, margin_size } = this.datas;
      return `
        height: ${button_size}px;
        line-height: ${button_size}px;
        poposition: fixed;
        bottom: ${over_bottom}px;
        padding: 0 ${margin_size}px;
        box-sizing: border-box;
      `;
    },
    button_style() {
      const { preview_color, text_size, text_color, radius_size } = this.datas;
      return `
        border-radius: ${radius_size}px;
        overflow: hidden;
        font-size: ${text_size}px;
        color: ${text_color};
        background-color: ${preview_color.color};
        background-image: url(${preview_color.isColor == 2 ? preview_color.image : ""});
        background-size: 100% auto;
        bakcground-position: center;
        `;
    },
    /** 标题 */
    title() {
      return this.datas.title || "";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    }
  },

  methods: {
    toUrl() {
      if (this.datas.clicktye && Number(this.datas.clicktye) == 2) {
        // 显示弹窗
        this.showPop = true;
        return;
      }
      let item = this.datas.link;
      let params = {};
      if (item.is_minApp == 2 && this.fun.isWindVane()) {
        // "appId":"小程序appid",
        params = { target: `wxmp://jumpmp:{"originId": ${item.gh_id},"path":${item.minApp_link},"extraData":{"from":"app"}}` };
        window.WindVane.call(
          "SBase",
          "navigationTo",
          params,
          function(e) {
            alert("navigationTo success:" + JSON.stringify(e));
          },
          function(e) {
            alert("navigationTo failure:" + JSON.stringify(e));
          }
        );
        return;
      }
      if (item.is_h5 == 2 && this.fun.isApp()) {
        YDB.MiniWX(item.gh_id, item.minApp_link);
        return;
      }
      if (item.is_h5 == 2 && this.fun.isCPS()) {
        let json = {
          mini_route: item.minApp_link,
          mini_id: item.gh_id
        };
        if (this.fun.isIosOrAndroid() === "ios") {
          miniWXIOS({ body: "miniWXIOS", json: JSON.stringify(json) });
        } else {
          miniWXAndroid(JSON.stringify(json));
        }
        return;
      }

      if (item.is_h5 == 7) {
        if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
          let json = { name: "task" };
          if (this.fun.isIosOrAndroid() === "ios") {
            toUrlIOS({ body: "toUrlIOS", json: JSON.stringify(json) });
          } else {
            toUrlAndroid(JSON.stringify(json));
          }
        } else if (item.link) {
          window.location.href = item.link;
        }
      } else if (item.is_h5 == 1 && item.link) {
        if (this.fun.isWindVane()) {
          params = { target: item.link };
          window.WindVane.call(
            "SBase",
            "navigationTo",
            params,
            function(e) {
              alert("navigationTo success:" + JSON.stringify(e));
            },
            function(e) {
              alert("navigationTo failure:" + JSON.stringify(e));
            }
          );
          return;
        }
        window.location.href = item.link;
      }
    },
    onCopy: function(e) {
      this.$toast.success({
        message: "已复制微信号",
        duration: 1500
      });
    },
    onError: function(e) {
      this.$toast.fail({
        message: "复制微信号失败",
        duration: 1500
      });
    }
  }
};
</script>

<style lang="scss" scoped>
// 默认
.component-wrapper {
  width: 100%;
}

.fixed-box {
  width: 100%;
  position: fixed;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;

  .btn {
    width: 100%;
    height: 100%;
    text-align: center;
  }
}
.w-100 {
  width: 9.375rem;
  display: block;
  margin: 0 auto;
}
</style>
